import 'package:commons/commons.dart';
import 'package:flutter/material.dart';

abstract class ITranslations extends Translations {
  @override
  Map<String, Map<String, String>> get keys => translations.isEmpty
      ? {}
      : {
          // 'zh_CN': translations
          //     .map(
          //         (e) => e.zhKeys.map((k, v) => MapEntry('${e.package}.$v', v)))
          //     .reduce((a, b) => {...a, ...b}),
          'es_US': translations
              .map(
                  (e) => e.enKeys.map((k, v) => MapEntry('${e.package}.$v', v)))
              .reduce((a, b) => {...a, ...b}),
        };

  List<BaseTranslations> get translations;
}

abstract class BaseTranslations {
  String get package;
  @required
  Map<String, String> get enKeys => {};
}

extension TranslationsEx on String {
  String trArgs(List args) {
    final l = split('{}');
    for (int i = 0; i < l.length; i++) {
      if (i % 2 == 0) {
        continue;
      }
      l[i] = args[i % 2];
    }
    return l.join('');
  }
}
